package com.ruoyi.asms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.ruoyi.asms.domain.AsmsFaultAsset;
import com.ruoyi.asms.domain.vo.FaultNumberAssetTypeVo;
import com.ruoyi.asms.domain.vo.ThisWeekFaultSQLVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 故障资产设备信息Mapper接口
 * 
 * @author yfkj
 * @date 2021-11-01
 */@Mapper
public interface AsmsFaultAssetMapper extends BaseMapper<AsmsFaultAsset>
{
    /**
     * 查询故障资产设备信息
     * 
     * @param faultAssetId 故障资产设备信息主键
     * @return 故障资产设备信息
     */
    public AsmsFaultAsset selectAsmsFaultAssetByFaultAssetId(Long faultAssetId);

    /**
     * 查询故障资产设备信息列表
     * 
     * @param asmsFaultAsset 故障资产设备信息
     * @return 故障资产设备信息集合
     */
    public List<AsmsFaultAsset> selectAsmsFaultAssetList(AsmsFaultAsset asmsFaultAsset);

    /**
     * 新增故障资产设备信息
     * 
     * @param asmsFaultAsset 故障资产设备信息
     * @return 结果
     */
    public int insertAsmsFaultAsset(AsmsFaultAsset asmsFaultAsset);

    /**
     * 修改故障资产设备信息
     * 
     * @param asmsFaultAsset 故障资产设备信息
     * @return 结果
     */
    public int updateAsmsFaultAsset(AsmsFaultAsset asmsFaultAsset);

    /**
     * 删除故障资产设备信息
     * 
     * @param faultAssetId 故障资产设备信息主键
     * @return 结果
     */
    public int deleteAsmsFaultAssetByFaultAssetId(Long faultAssetId);

    /**
     * 批量删除故障资产设备信息
     * 
     * @param faultAssetIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAsmsFaultAssetByFaultAssetIds(Long[] faultAssetIds);

    public List<FaultNumberAssetTypeVo> getFaultNumberbyAssetType(@Param("maintenanceDeptId") Long maintenanceDeptId, @Param("useDeptId") Long useDeptId,
                                                                  @Param("assetTypeId") Long assetTypeId);
    @Select("SELECT " +
            "count(*) AS num, " +
            "FROM_UNIXTIME(create_time / 1000, '%w') AS weekday " +
            "FROM " +
            "asms_fault_asset " +
            "WHERE " +
            "maintenance_dept_id = #{mDeptId} " +
            "AND is_finish = 0 " +
            "AND create_time >= #{startTime} " +
            "AND create_time <= #{endTime} " +
            "GROUP BY " +
            "weekday;")
    List<ThisWeekFaultSQLVo> getOneWeekFaultNum(@Param("startTime") Long startTime, @Param("endTime") Long endTime,
                                                @Param("mDeptId") Long mDeptId);
}
